home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / prog / graphics / seg_intersect.c < prev    next >
C/C++ Source or Header  |  1994-08-05  |  2KB  |  86 lines

  1. #include <LEDA/sweep_segments.h>
  2. #include <LEDA/window.h>
  3.  
  4.  
  5. main()
  6.   window W(700,800);
  7.  
  8.   int input;
  9.   int grid_width = 0;
  10.   int line_width = 1;
  11.   int node_width = 3;
  12.   int N = 100;
  13.  
  14.   panel P("SEGMENT_INTERSECTION");
  15.  
  16.   P.int_item("SEGMENTS", N);
  17.   P.choice_item("INPUT", input,"mouse","random");
  18.   P.int_item("GRID",grid_width,0,40,10);
  19.   P.int_item("line width",line_width,1,5);
  20.   P.int_item("node width",node_width,1,5);
  21.  
  22.  
  23. for(;;)
  24. {
  25.   P.open(0,0);
  26.  
  27.   W.init(-1200,1200,-1200, grid_width);
  28.  
  29.   W.set_node_width(node_width);
  30.   W.set_line_width(line_width);
  31.  
  32.   list<segment> seglist1,seglist2;
  33.  
  34.   if (input) 
  35.    { 
  36.      init_random();
  37.  
  38.      double ymax = W.ymax()-4*20/W.scale()-100;
  39.  
  40.      int xmin = int(W.xmin())+100;
  41.      int xmax = int(W.xmax())-100;
  42.  
  43.      for(int i = 0; i < N; i++)
  44.      { double x1 = random(xmin,-100);
  45.        double y1 = random(-1000,int(ymax));
  46.        double x2 = random(100,xmax);
  47.        double y2 = random(-1000,int(ymax));
  48.        segment s(x1,y1,x2,y2);
  49.        W << s;
  50.        seglist1.append(s);
  51.       }
  52.     }
  53.   else // mouse input
  54.     { segment s;
  55.  
  56.       while (W >> s)
  57.       { W << s;
  58.         seglist1.append(s);
  59.        }
  60.  
  61.      }
  62.  
  63.  
  64.   GRAPH<point,int> SUB;
  65.   node v;
  66.  
  67.   W.message("Computing Arrangement");
  68.   float T = used_time();
  69.  
  70.   SWEEP_SEGMENTS(seglist1,seglist2,SUB);
  71.  
  72.   W.message(string("# = %d   T = %6.2f sec",
  73.                    SUB.number_of_nodes(),
  74.                    used_time(T))
  75.             );
  76.  
  77.   forall_nodes(v,SUB) W.draw_filled_node(SUB[v]);
  78.  
  79. } // for(;;)
  80.  
  81.   return 0;
  82.  
  83. }
  84.  
  85.